﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HGManager
{
    public partial class frmThemDonVi : Form
    {
        private CommonConnect cc = new CommonConnect();
        SqlConnection conn = null;
        public frmThemDonVi()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            conn = cc.Connected();
            InitializeComponent();

        }

        private void btnDong_Click(object sender, EventArgs e)
        {

            frmDonViTinh _frmDonViTinh = new frmDonViTinh();
            _frmDonViTinh.Show();
            Close();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (!txtMa.Text.Equals(""))
            {
                // Thực hiện truy vấn
                string insert = "Insert Into tblDonViTinh(fldMa, fldTen, fldGhiChu)" +
                                "Values('" + txtMa.Text + "',N'" + txtTen.Text + "','" +
                                txtGhiChu.Text + "')";
                SqlCommand cmd = new SqlCommand(insert, conn);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Thêm mới thành công", "Thông báo!");

                // Trả tài nguyên

                cmd.Dispose();
                Close();
                frmDonViTinh _frmDonViTinh = new frmDonViTinh();
                _frmDonViTinh.Show();
            }
            else {
                MessageBox.Show("Kiểm tra lại!", "Thông báo!");
            }
        }
    }
}
